package panda.query.test;

import panda.query.scan.Scanner;
import panda.query.struct.Attribute;
import panda.query.tree.QueryTreeNode;
import panda.server.Panda;
import panda.transaction.Transaction;

public class SQLBTOrder {
	public static void main(String args[]) {
		Panda.init("f:/data2");

		Transaction tx = new Transaction();
		long time = -System.currentTimeMillis();
		Panda.getPlanner().executeUpdate("CREATE TABLE table1(a INT, b INT)", tx);
		Panda.getPlanner().executeUpdate("INSERT INTO table1 VALUES (1, 3)", tx);
		Panda.getPlanner().executeUpdate("INSERT INTO table1 VALUES (2, 2)", tx);
		Panda.getPlanner().executeUpdate("INSERT INTO table1 VALUES (3, 3)", tx);
		Panda.getPlanner().executeUpdate("INSERT INTO table1 VALUES (4, 2)", tx);
		Panda.getPlanner().executeUpdate("INSERT INTO table1 VALUES (5, 4)", tx);
		
		System.out.println("BEGIN QUERY");
		QueryTreeNode tn = Panda.getPlanner().executeQuery("SELECT DISTINCT b FROM table1 ORDER BY a", tx);
		Scanner s = tn.open();
		
		Attribute a = tn.getSchema().getAttributeByName("column0");
		while (s.next()) {
			System.out.println(s.getValue(a).getContentValue());
		}
		
		time += System.currentTimeMillis();
		System.out.println(time);
	}
}
